package com.jyy.prefabricated.task;

import com.jyy.prefabricated.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;

/**
 * @version 1.0.0
 * @author: zjj
 */
@Slf4j
@Component
public class task {

    @Autowired
    private ExamService examService;

    @Autowired
    private StudentExamService studentExamService;

    @Autowired
    private CompanyAdService companyAdService;
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private StudentAchievementService studentAchievementService;
    @Autowired
    private CourseService courseService;

    @Autowired
    private ViewLogService viewLogService;

    @Scheduled(cron = "0 0/1 * * * ? ")
    public void checkExamStatus(){
        log.info("开始执行定时检查考试状态任务,每分钟执行");
        examService.checkExamStatus();
    }

    @Scheduled(cron = "0 0/1 * * * ? ")
    public void initPaper(){
        log.info("开始执行定时生成10分钟后开始考试的试卷信息,每分钟执行");
        studentExamService.initPaperEarly(10);
    }


    @Scheduled(cron = "0 0 0/1 * * ?  ")
    public void checkAdStatus(){
        log.info("开始执行定时检查广告状态是否过期,每小时执行");
        companyAdService.checkAdStatus();
    }
    @Scheduled(cron = "0 0 0/1 * * ?  ")
    public void issueCertificates(){
        log.info("开始执行定时考试发放证书,每小时执行");
        studentExamService.issueCertificates();
    }
    @Scheduled(cron = "0 0 1 * * ?  ")
    public void invalidCertificates() throws IOException, NoSuchAlgorithmException {
        log.info("开始执行定时刷新失效证书,每天1:00执行");
        studentExamService.invalidCertificates();
    }
//    @Scheduled(cron = "0 0/1 * * * ? ")
    @Scheduled(cron = "0 0 0/1 * * ?  ")
    public void initCourseSecond() throws Exception {
        log.info("开始执行定时检测更新课程章节时长,每小时执行");
        courseService.checkCourseSecond();
    }

    /*@Scheduled(cron = "1 0 0 * * ?  ")
    public void viewLog() throws IOException, NoSuchAlgorithmException {
        log.info("开始执行定时更新观看日志,每天00:00:01执行");
        viewLogService.viewLog();
    }*/
//    @Scheduled(cron = "0 0 0/1 * * ?  ")
//    public void checkOrders(){
//        log.info("开始执行定时小鹅通订单,每小时执行");
//        orderInfoService.pullOrders();
//    }
//    @Scheduled(cron = "0 15 1 ? * *")
//    public void combinedResults(){
//        log.info("开始执行刷新合并成绩");
//        studentAchievementService.combinedResults();
//    }
}
